package LeetCode;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/14.
//
//https://leetcode.cn/problems/count-and-say/description/
public class 外观数列 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = countAndSay(scan.nextInt());
        System.out.println(str);
    }
    public static String countAndSay(int n) {
        Map<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            map.put((char) ('0' + i),0);
        }
//        for (Character i : map.keySet()) {
//            System.out.println("key: " + i + " value: " + map.get(i));
//        }
        String num = "1";
        for (int i = 0; i < n - 1; i++) {
            char[] str = num.toCharArray();
            int point = 0;
            StringBuilder s = new StringBuilder()
;            while (point < str.length){
                map.replace(str[point],map.get(str[point])+1);
//                map.put(str[point],map.get(str[point])+1);
                if(point == str.length-1 || str[point+1] != str[point]){
                    s.append(map.get(str[point]));
                    s.append(str[point]);
                    map.replace(str[point],0);
                }
                point++;
            }
            num = String.valueOf(s);
        }
        return num;
    }
}
